package com.work.game.home;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.android.volley.Request;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.gson.Gson;
import com.gyf.immersionbar.ImmersionBar;
import com.umeng.commonsdk.UMConfigure;
import com.work.game.R;
import com.work.game.ad.MediationBannerAd;
import com.work.game.ad.MediationTablePlaqueAd;
import com.work.game.ad.kaku.TaKuRewardAdCallback;
import com.work.game.ad.kaku.banner.TaKuBannerAdFour;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdGoodDetail;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdHome;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdOne;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdOneCW;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdOneDT;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdOneJL;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdProCenter;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdRewardRecord;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdSignIn;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdThree;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdTwo;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdWithdrawal;
import com.work.game.ad.kaku.interstitia.TaKuInterstitialAdWithdrawalRecord;
import com.work.game.ad.kaku.nativie.TaKuNativeAdCate;
import com.work.game.ad.kaku.nativie.TaKuNativeAdGoodDetail;
import com.work.game.ad.kaku.nativie.TaKuNativeAdHome;
import com.work.game.ad.kaku.nativie.TaKuNativeAdHome2;
import com.work.game.ad.kaku.nativie.TaKuNativeAdOneCW;
import com.work.game.ad.kaku.nativie.TaKuNativeAdOneDT;
import com.work.game.ad.kaku.nativie.TaKuNativeAdOneJL;
import com.work.game.ad.kaku.nativie.TaKuNativeAdProCenter;
import com.work.game.ad.kaku.nativie.TaKuNativeAdSignIn;
import com.work.game.ad.kaku.nativie.TaKuNativeAdTwo;
import com.work.game.ad.kaku.reward.TaKuRewardAd;
import com.work.game.ad.kaku.reward.TaKuRewardAdOne;
import com.work.game.ad.kaku.reward.TaKuRewardAdSignIn;
import com.work.game.ad.kaku.reward.TaKuRewardAdWithdrawal;
import com.work.game.adapter.ViewPageAdapter;
import com.work.game.config.UrlConfig;
import com.work.game.home.fragment.CategoryFragment;
import com.work.game.home.fragment.ContentFragment;
import com.work.game.home.fragment.HomeFragment;
import com.work.game.home.fragment.MyFragmentStyle2;
import com.work.game.home.ui.enums.RedisEnum;
import com.work.game.home.ui.enums.RiskEnum;
import com.work.game.home.ui.model.User;
import com.work.game.home.ui.model.vo.UserDailyActivityVo;
import com.work.game.service.RiskService;
import com.work.game.utils.StringSplit;
import com.work.game.utils.VersionUtils;
import com.work.game.utils.risk.DeviceUtils;
import com.work.game.utils.risk.RiskUtils;
import com.work.game.utils.risk.VirtualApkCheckUtil;
import com.work.game.view.NavigationTabBar;
import com.work.game.volley.BaseActivity;
import com.work.game.volley.state.HUCState;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * Created by GIGAMOLE on 28.03.2016.
 */
public class HorizontalNtbActivity extends BaseActivity {
    private SharedPreferences sp;
    private NavigationTabBar navigationTabBar;
    private VirtualApkCheckUtil virtualApkCheckUtil;
    private RiskUtils riskUtils;
    private DeviceUtils deviceUtils;

    private MediationBannerAd mediationBannerAd;
    private MediationTablePlaqueAd mediationTablePlaqueAd;

    @RequiresApi(api = Build.VERSION_CODES.S)
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_horizontal_ntb);
        virtualApkCheckUtil = VirtualApkCheckUtil.getSingleInstance();
        deviceUtils = DeviceUtils.getInstance();
        riskUtils = RiskUtils.getInstance();
        initAd();
        //initUI();
        initUi2();
        load();
        String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
        if (RedisEnum.TA_KU.getValue().equals(key)) {
            //初始化插屏
            TaKuInterstitialAdHome taKuInterstitialAdHome = TaKuInterstitialAdHome.getInstance();

            taKuInterstitialAdHome.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,0));
            TaKuInterstitialAdThree taKuInterstitialAdThree = TaKuInterstitialAdThree.getInstance();
            taKuInterstitialAdThree.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,1));
            TaKuInterstitialAdOneDT taKuInterstitialAdOneDT = TaKuInterstitialAdOneDT.getInstance();
            taKuInterstitialAdOneDT.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,2));
            TaKuInterstitialAdOneCW taKuInterstitialAdOneCW = TaKuInterstitialAdOneCW.getInstance();
            taKuInterstitialAdOneCW.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,3));
            TaKuInterstitialAdOneJL taKuInterstitialAdOneJL = TaKuInterstitialAdOneJL.getInstance();
            taKuInterstitialAdOneJL.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,4));
            TaKuInterstitialAdTwo taKuInterstitialAdTwo = TaKuInterstitialAdTwo.getInstance();
            taKuInterstitialAdTwo.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,5));
            TaKuInterstitialAdSignIn taKuInterstitialAdSignIn = TaKuInterstitialAdSignIn.getInstance();
            taKuInterstitialAdSignIn.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,6));
            TaKuInterstitialAdProCenter taKuInterstitialAdProCenter = TaKuInterstitialAdProCenter.getInstance();
            taKuInterstitialAdProCenter.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,7));
            TaKuInterstitialAdWithdrawal taKuInterstitialAdWithdrawal = TaKuInterstitialAdWithdrawal.getInstance();
            taKuInterstitialAdWithdrawal.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,8));
            TaKuInterstitialAdWithdrawalRecord taKuInterstitialAdWithdrawalRecord = TaKuInterstitialAdWithdrawalRecord.getInstance();
            taKuInterstitialAdWithdrawalRecord.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,9));
            TaKuInterstitialAdRewardRecord taKuInterstitialAdRewardRecord = TaKuInterstitialAdRewardRecord.getInstance();
            taKuInterstitialAdRewardRecord.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,10));
            TaKuInterstitialAdOne taKuInterstitialAdOne = TaKuInterstitialAdOne.getInstance();
            taKuInterstitialAdOne.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,11));
            TaKuInterstitialAdGoodDetail taKuInterstitialAdGoodDetail = TaKuInterstitialAdGoodDetail.getInstance();
            taKuInterstitialAdGoodDetail.loadAd(this,  StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()),StrUtil.COMMA,12));
            //初始化信息流
            TaKuNativeAdOneDT taKuNativeAdOneDT = TaKuNativeAdOneDT.getInstance();

            taKuNativeAdOneDT.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,0));
            TaKuNativeAdOneJL taKuNativeAdOneJL = TaKuNativeAdOneJL.getInstance();
            taKuNativeAdOneJL.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,1));
            TaKuNativeAdOneCW taKuNativeAdOneCW = TaKuNativeAdOneCW.getInstance();
            taKuNativeAdOneCW.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,2));
            TaKuNativeAdTwo taKuNativeAdTwo = TaKuNativeAdTwo.getInstance();
            taKuNativeAdTwo.loadAd(this,StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,3));
            TaKuNativeAdSignIn taKuNativeAdSignIn = TaKuNativeAdSignIn.getInstance();
            taKuNativeAdSignIn.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,4));
            TaKuNativeAdProCenter taKuNativeAdProCenter = TaKuNativeAdProCenter.getInstance();
            taKuNativeAdProCenter.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,5));
            TaKuNativeAdGoodDetail taKuNativeAdGoodDetail = TaKuNativeAdGoodDetail.getInstance();
            taKuNativeAdGoodDetail.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,6));
            TaKuNativeAdHome taKuNativeAdHome = TaKuNativeAdHome.getInstance();
            taKuNativeAdHome.loadAd(this,StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,7));
            TaKuNativeAdCate taKuNativeAdCate = TaKuNativeAdCate.getInstance();
            taKuNativeAdCate.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,8));
            TaKuNativeAdHome2 taKuNativeAdHome2 = TaKuNativeAdHome2.getInstance();
            taKuNativeAdHome2.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()),StrUtil.COMMA,9));

            //初始化激励视频
            TaKuRewardAdOne taKuRewardAdOne = TaKuRewardAdOne.getInstance();

            taKuRewardAdOne.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()),StrUtil.COMMA,0));
            TaKuRewardAdSignIn taKuRewardAdSignIn = TaKuRewardAdSignIn.getInstance();
            taKuRewardAdSignIn.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()),StrUtil.COMMA,1));
            TaKuRewardAdWithdrawal taKuRewardAdWithdrawal = TaKuRewardAdWithdrawal.getInstance();
            taKuRewardAdWithdrawal.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()),StrUtil.COMMA,2));
            TaKuRewardAd taKuRewardAd = TaKuRewardAd.getInstance();
            taKuRewardAd.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()),StrUtil.COMMA,3));

            TaKuRewardAdCallback taKuRewardAdCallback = TaKuRewardAdCallback.getInstance();
            taKuRewardAdCallback.setUserId(getSharedPreferences("id"));
            taKuRewardAdCallback.setToken(getSharedPreferences("deviceId"));
            taKuRewardAdCallback.loadAd(this, getSharedPreferences(RedisEnum.INCENTIVE_VIDEO_CALLBACK.getKey()));
        } else {
            //初始化 插屏广告
            mediationTablePlaqueAd = MediationTablePlaqueAd.getInstance();
            mediationTablePlaqueAd.init(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()));
            mediationTablePlaqueAd.loadCacheInterstitialFullAd(this);

            //初始化 Banner
            mediationBannerAd = MediationBannerAd.getInstance();
            mediationBannerAd.init(this, getSharedPreferences(RedisEnum.BANNER.getKey()), 200);
            mediationBannerAd.loadCacheBannerAd();
        }
    }//

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.runFinalization();
        Runtime.getRuntime().gc();
        System.gc();
    }

    private void initUI() {
        final ViewPager viewPager = findViewById(R.id.vp_horizontal_ntb);
        final String[] colors = getResources().getStringArray(R.array.default_preview);
        navigationTabBar = findViewById(R.id.ntb_horizontal);
        final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
        List<Fragment> fragments = new ArrayList<>();
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_home), getResources().getColor(R.color.sel_menu_color), "首页"));
//        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.mipmap.icon_cate), Color.parseColor(colors[2]), "分类"));
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_answer), getResources().getColor(R.color.sel_menu_color), "答题"));
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_my), getResources().getColor(R.color.sel_menu_color), "我的"));
        navigationTabBar.setModels(models);
        fragments.add(new HomeFragment());
//        fragments.add(new CategoryFragment());
        fragments.add(new ContentFragment());
//        fragments.add(new MyFragment());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && fragments.size() > 2) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.home));
        }
        final ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(viewPageAdapter);
        navigationTabBar.setViewPager(viewPager, 0);
        navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(final int position) {
                navigationTabBar.getModels().get(position).hideBadge();
                //  fragments.get(position).setUserVisibleHint(true);
            }

            @Override
            public void onPageScrollStateChanged(final int state) {

            }
        });
/*
        navigationTabBar.post(new Runnable() {
            @Override
            public void run() {
                final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
                bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
                bgNavigationTabBar.requestLayout();
            }
        });*/

    }

    private void initUi2(){
        final ViewPager viewPager = findViewById(R.id.vp_horizontal_ntb);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new CategoryFragment());
        fragments.add(new ContentFragment());
        fragments.add(new MyFragmentStyle2());
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && fragments.size() > 2) {
//            Window window = getWindow();
//            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            window.setStatusBarColor(getResources().getColor(R.color.home));
//        }
        ImmersionBar.with(this).statusBarDarkFont(true).init();
        final ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(viewPageAdapter);
        BottomNavigationView bottomNavigationView=findViewById(R.id.bottom_menu);
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.menu_1:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.menu_2:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.menu_3:
                        viewPager.setCurrentItem(2);
                        break;
                    case R.id.menu_4:
                        viewPager.setCurrentItem(3);
                        break;
                }
                return false;
            }
        });
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                MenuItem item = bottomNavigationView.getMenu().getItem(position);
                item.setChecked(true);
                bottomNavigationView.setSelectedItemId(bottomNavigationView.getMenu().getItem(position).getItemId());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // 处理返回的数据
        load();
    }
    //获取用户设备信息ACTIVATION_NOTIFICATION_OPENED

    private void load() {
        loading();
        UserDailyActivityVo baseVo = new UserDailyActivityVo();
        //双开2.0版本
        Intent serviceIntent = new Intent(this, RiskService.class);
        serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startService(serviceIntent);
        //是否分身
        boolean flag = virtualApkCheckUtil.checkByCreateLocalServerSocket(deviceUtils.getPackageName(this));
        baseVo.setUdaSeparation(String.valueOf(flag ? 1 : 2));
        //是否模拟器
        flag = riskUtils.detectEmulator(this);
        baseVo.setUdaSimulator(String.valueOf(flag ? 1 : 2));
        //是否开启调试模式
        flag = deviceUtils.isDeveloperModeEnabled(this);
        baseVo.setUdaDebugMode(String.valueOf(flag ? 1 : 2));
        //是否USB调试模式
        flag = deviceUtils.isAdbEnabled(this);
        baseVo.setUdaUsbMode(String.valueOf(flag ? 1 : 2));
        //是否root
        flag = deviceUtils.isDeviceRooted(this);
        baseVo.setUdaRoot(String.valueOf(flag ? 1 : 2));
        //是否开启无障碍模式
        flag = deviceUtils.isAccessibilityServiceEnabled(this);
        baseVo.setUdaAccessibility(String.valueOf(flag ? 1 : 2));
        //是否开启VPN代理模式
        flag = deviceUtils.isWifiProxy();
        baseVo.setUdaVpnProxy(String.valueOf(flag ? 1 : 2));
        //运营环境当前电池
        baseVo.setUdaBattery(String.valueOf(riskUtils.checkBatteryManager(this)));
        //包名
        baseVo.setUdaPackage(deviceUtils.getPackageName(this));
        //APP名称
        baseVo.setUdaAppName(deviceUtils.getAppName(this));
        //版本号
        baseVo.setUdaVersionCode(VersionUtils.getAppVersionName(this));
        //SIM状态
        baseVo.setUdaSimStatus(String.valueOf(deviceUtils.getSim(this)));
        //SIM运营商
        baseVo.setUdaSimOperator(deviceUtils.getNetworkOperatorName(this));
        //当前网络
        baseVo.setUdaNetWork(deviceUtils.getNetworkTypeName(this));
        //Android版本号
        baseVo.setUdaAndroid(deviceUtils.getSystemAndroidVersionCode());
        //Mac地址
        baseVo.setUdaMac(deviceUtils.getMacAddr(this));
        //手机品牌
        baseVo.setUdaBrand(deviceUtils.getSystemAndroidMobilePhoneBrand());
        //手机型号&软件版本
        baseVo.setUdaSystemVersionCode(deviceUtils.getSystemAndroidSystemVersionCode());
        //手机应用总数
        List<PackageInfo> packageInfoList = DeviceUtils.getInstance().getAllApps(this);
        baseVo.setUdaAllApp(String.valueOf(ObjectUtil.isNotEmpty(packageInfoList) ? packageInfoList.size() : 0));
        List<UserDailyActivityVo> userDailyActivityVoList = new ArrayList<>();
        for (PackageInfo packageInfo : packageInfoList) {
            UserDailyActivityVo userDailyActivityVo = new UserDailyActivityVo();
            String name = deviceUtils.getAppName(this, packageInfo.packageName);
            userDailyActivityVo.setUdaPackage(packageInfo.packageName);
            userDailyActivityVo.setUdaAppName(name);
            userDailyActivityVo.setUdaVersionCode(packageInfo.versionName);
            userDailyActivityVoList.add(userDailyActivityVo);
        }
        // 创建 Gson 实例
        Gson gson = new Gson();
        // 将 User 对象转换为 JSON 字符串
        String jsonString = gson.toJson(userDailyActivityVoList);
        //应用JSON明细
        baseVo.setUdaAllAppDetail(jsonString);

//        //系统应用
//        List<PackageInfo> packageInfoListSystem = DeviceUtils.getInstance().getAllSystemApps(this);
//        baseVo.setUdaSystemAllApp(String.valueOf(ObjectUtil.isNotEmpty(packageInfoListSystem) ? packageInfoListSystem.size() : 0));
//        List<UserDailyActivityVo> userDailyActivityVoSystemList = new ArrayList<>();
//        for (PackageInfo packageInfo : packageInfoListSystem) {
//            UserDailyActivityVo userDailyActivityVo = new UserDailyActivityVo();
//            String name = deviceUtils.getAppName(this, packageInfo.packageName);
//            userDailyActivityVo.setUdaPackage(packageInfo.packageName);
//            userDailyActivityVo.setUdaAppName(name);
//            userDailyActivityVo.setUdaVersionCode(packageInfo.versionName);
//            userDailyActivityVoSystemList.add(userDailyActivityVo);
//        }
//        // 将 User 对象转换为 JSON 字符串
//        String jsonSystemString = gson.toJson(userDailyActivityVoSystemList);
//        baseVo.setUdaSystemAllAppDetail(jsonSystemString);
        baseVo.setUmToken(UMConfigure.getUmengZID(this));

        baseVo.setToken(getSharedPreferences("deviceId"));
        hucRequestInterfase.executeStr(this, User.class, HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.INFO_URL, hucParameInterfase.getRequestParameter(baseVo), true);
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                loadDismiss();
                if (!(response instanceof User)) {
                    showToast(response.toString());
                    return;
                }
                User users = (User) response;
                setSharedPreferences("id", users.getId());
                setSharedPreferences("deviceId", users.getOpenid() + users.getDeviceId());
                setSharedPreferences("loginTime", users.getLoginTime());
                setSharedPreferences("signInNumber", users.getSignInNumber());
                setSharedPreferences("signIdDayNumber", users.getSignIdDayNumber());
                setSharedPreferences("afbPhone", users.getAfbPhone());
                setSharedPreferences("afbName", users.getAfbName());
                setSharedPreferences("code", users.getCode());
                setSharedPreferences("moneyRedPacket", users.getMoneyRedPacket());
                setSharedPreferences("moneyGoldCoin", users.getMoneyGoldCoin());
                setSharedPreferences("nickname", users.getNickname());
                setSharedPreferences("usParentId", users.getUsParentId());
                String index = getSharedPreferences("currentSubject");
                setSharedPreferences("currentSubject", StrUtil.isNotEmpty(index) ? index : "0");
                String answerCount = getSharedPreferences("answerCount");
                setSharedPreferences("answerCount", StrUtil.isNotEmpty(answerCount) ? answerCount : "0");
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS.getKey(), users.getRisk_advertising_coins());
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS_THAN_EQUAL.getKey(), users.getRisk_advertising_coins_than_equal());
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS_THAN_EQUAL_TWO.getKey(), users.getRisk_advertising_coins_than_equal_two());
                setSharedPreferences(RedisEnum.RISK_WHITE_LIST.getKey(), users.getRisk_white_list());
                break;
        }
    }


    private void initAd() {
//        ViewGroup viewGroup = findViewById(R.id.fl_content);
//        String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
//        if (RedisEnum.TA_KU.getValue().equals(key)) {
//            TaKuBannerAdFour taKuBannerAdFour = TaKuBannerAdFour.getInstance();
//            taKuBannerAdFour.setToken(getSharedPreferences("deviceId"));
//            taKuBannerAdFour.load(this, getSharedPreferences(RedisEnum.BANNER.getKey()).split(",")[5], viewGroup);
//        } else {
//            MediationBannerAd mediationBannerAd = MediationBannerAd.getInstance();
//            mediationBannerAd.setViewGroup(viewGroup);
//            mediationBannerAd.showCacheBannerView();
//        }
    }
}
